package gcd;

import java.util.Random;

public class Main {

	public static void main(String[] args) {
		long bruteTimeAvg = 0;
		long bruteTimeMax = 0;
		
		long euclidianTimeAvg = 0;
		long euclidianTimeMax = 0;
		
		int tries = 100000;
		int maxN = 10000000;
		Random random = new Random();
		System.out.println("Start");
		long cycleStart = System.nanoTime();
		for (int i = 0; i < tries; i++) {
			if (tries > 100) if (i % (tries / 100) == 0) System.out.print(".");
			int a = random.nextInt(maxN)+1;
			int b = random.nextInt(maxN)+1;
			
			long start = System.nanoTime();
			BruteGCD.find(a, b);
			long end = System.nanoTime();
			long runTime = end - start;
			if (bruteTimeMax < runTime) bruteTimeMax = runTime;
			bruteTimeAvg += runTime;
		}
		long cycleTime = System.nanoTime() - cycleStart;
		System.out.println();
		System.out.println("Brute cycle time: "+cycleTime);
		bruteTimeAvg /= tries;
		System.out.println("Brute force average time: "+bruteTimeAvg);
		System.out.println("Brute force max time: "+bruteTimeMax);
		cycleStart = System.nanoTime();
		for (int i = 0; i < tries; i++) {
			if (i % (tries / 100) == 0) System.out.print(".");
			int a = random.nextInt(maxN)+1;
			int b = random.nextInt(maxN)+1;

			long start = System.nanoTime();
			EuclidianGCD.find(a, b);
			long end = System.nanoTime();
			long runTime = end - start;
			if (euclidianTimeMax < runTime) euclidianTimeMax = runTime;
			euclidianTimeAvg += runTime;
		}
		cycleTime = System.nanoTime() - cycleStart;
		System.out.println();
		System.out.println("Euclidian cycle time: "+cycleTime);
		euclidianTimeAvg /= tries;
		System.out.println("Euclidian algorithm average time: "+euclidianTimeAvg);
		System.out.println("Euclidian algorithm max time: "+euclidianTimeMax);
	}

}
